<?php

namespace App\Http\Controllers\Mobile\Company;
use App\Http\Requests\Company\Basic\MobileBasicRequest;
use App\Models\Company\CompanyBasic;
use Illuminate\Http\Request;
use Auth,Style;
class RegisterController extends CommonController{

    /**
     * 注册基本信息
     * @param Request $request
     * @return mixed
     */
    public function registerBasic(Request $request){
        $userInfo = auth()->guard('company')->user();
        return Style::view('mobile.company.registerBasic',compact('userInfo'));
    }

    /**
     * ajax验证登录
     * @param MobileBasicRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function postRegisterBasic(MobileBasicRequest $request){
        $input = $request->only('company_name', 'brands', 'comkind', 'industry', 'established', 'employee_num', 'temptation','profile',
            'contacts','mobile','phone','fax','email','qq','region','address','website','lines');
        //获取用户信息ID
        $userInfo = auth()->guard('company')->user();
        $input['updatetime'] = date('Y-m-d H:i:s',time());

        if($request->input('id')){
            $companyBasic = CompanyBasic::where('uid',$userInfo->uid)->where('id',$request->input('id'))->count();
            if($companyBasic){
                CompanyBasic::where('uid',$userInfo->uid)->where('id',$request->input('id'))->update($input);
                return redirect('mobile/company/basic_info')->with('ok',"保存成功");
            }else{
                return Style::view('errors.404', ['exception' => '错误未知id...'], 404);
            }
        }else{
            $input['uid'] = $userInfo->uid;
            $input['addtime'] = date('Y-m-d H:i:s',time());
            CompanyBasic::create($input);
            return redirect('mobile/company/welcome');
        }
    }
}